// 获取上料树接口
const IgetMaterialTree = 'a/workstageparamrecord/workstageParamRecord/loadedmaterialtree'
// 根据周转码获取序列号列表: GET?turnoverNumber=?????
const IgetSerialNumber = 'a/turnovermaterialserialnumber/turnoverMaterialSerialNumber/getserialnumberbyturnovernumber'
//   根据子物料的批次号或序列号获取该子物料的任务号:  POST{"turnoverNumber:xxx, serialNumber:yyy"}
const IgetTaskNumber = 'a/workstageactualmaterial/workstageActualMaterial/gettasknumber'

/**
 * @author liubaohui
 * @description 产品履历树请求
 */
let ResumeTreeService = {
  methods: {
    /**
     * 获取上料树
     * @returns {Promise<Array>}
     */
    getMaterialTree(taskNumber) {
      let req = {
        method: 'post',
        url: IgetMaterialTree,
        data: {
          // taskNumber: '508N-2019-03N-22'
          taskNumber: taskNumber
        },
        noCommit: true
      }
      return this.$store.dispatch('saveData', req)
        .then(res => {
          return res.data
        }).catch(() => {
          return []
          // return mockMaterialTree
        })
    },
    /**
     * 根据周转码获取序列号列表
     * @returns {Promise<Array>}
     */
    getSerialNumbers() {
      let req = {
        method: 'get',
        url: IgetSerialNumber,
        params: {
          turnoverNumber: this.keyword,
        },
        noCommit: true
      }
      return this.$store.dispatch('saveData', req)
        .then(res => {
          return res.data
        }).catch(() => {
          return []
        })
    },
    /**
     * 根据周转码+序列号获取任务号
     * @returns {Promise<Array>}
     */
    getTaskNumbers() {
      let data = {}
      if (this.searchType === 1) {
        data = {
          turnoverNumber: this.keyword,
          serialNumber: this.serialNumber
        }
      }
      if (this.searchType === 2) {
        data = {
          serialNumber: this.keyword
        }
      }
      let req = {
        method: 'post',
        url: IgetTaskNumber,
        data: data,
        noCommit: true
      }
      return this.$store.dispatch('saveData', req)
        .then(res => {
          return res.data
        }).catch(() => {
          return []
        })
    }
  }
}

export default ResumeTreeService
